<template>
	<view class="page">
		<view class="header">
			<image class="header-icon" src="/static/ranking/trophy.png"></image>
			<text class="header-title"> 排行榜</text>
			<text class="header-date">{{genderId==1?'男子':'女子'}}{{typeId==1?'ftp功率':'最大功率'}}</text>
		</view>
		<view class="ranking-list" v-if="list.length>0">
			<view class="ranking">
				<view class="rangking-title">
					<text>排名</text>
					<text>昵称</text>
					<text>功率</text>
				</view>
				<view class="ranking-list">
					<view class="ranking-list-item" v-for="(item, key) in list" :key="key">
						<view v-if="key < 3" class="ranking-list-number">
							<image :src="'/static/ranking/' + (key + 1) + '.png'"></image>
						</view>
						<view v-else class="ranking-list-number">
							<text>{{key + 1}}</text>
						</view>
						<view class="ranking-list-nickname">
							<image :src="item.preview_url"></image>
							<text>{{item.nick_name}}</text>
						</view>
						<text class="ranking-list-score">{{typeId==1?item.ftp:item.maxpower}}</text>
					</view>
				</view>
			</view>
		</view>
		
		<empty v-if="!list.length" :isLoading="isLoading" tips="亲，暂时还没有用户数据哦" />
		
	</view>
</template>

<script>
import * as api from '@/api/ranking'
import Empty from '@/components/empty'

export default {
	components: {
	  Empty
	},
	data() {
	  return {
	    // 当前文章分类ID
	    genderId:0,
		typeId:0,
	    list:[],
		// 正在加载
		isLoading: true,
	  }
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
	  const app = this
	  // 记录文章分类ID
	  app.genderId = options.genderId
	  app.typeId = options.typeId
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
	  // 获取页面数据
	  this.getList()
	},
	methods: {
		getList() {
		  const app = this
		  return new Promise((resolve, reject) => {
		    api.list({ gender: app.genderId, type: app.typeId })
		      .then(result => {
		        // 合并新数据
		        app.list = result.data.list
				resolve(result)
		      })
		      .catch(reject)
			  .finally(() => app.isLoading = false)
		  })
		},
	}
}
</script>

<style lang="scss">
	page{
		background: #E32248;
	}
	
	.page{
		padding-bottom: 20rpx;
		
		.header{
			display: flex;
			flex-direction: column;
			color: #fff;
			padding: 25rpx;
			position: relative;
			
			.header-icon{
				position: absolute;
				top: 25rpx;
				right: 25rpx;
				width: 160rpx;
				height: 160rpx;
			}
			
			.header-title{
				font-size: 40px;
				font-weight: bold;
				margin-bottom: 20rpx;
			}
			
			.header-date{
				font-size: 12px;
				color: #d6d6d6;
			}
		}
		
		.ranking{
			width: 700rpx;
			border-radius: 30rpx;
			margin: auto;
			background: #fff;
			box-sizing: border-box;
			padding: 20rpx;
			
			.rangking-title{
				display: flex;
				font-size: 14px;
				color: #555;
				height: 50rpx;
				line-height: 50rpx;
				
				text{
					display: block;
					width: 100rpx;
					text-align: center;
					
					&:nth-child(2){
						box-sizing: border-box;
						padding-left: 20rpx;
						text-align: left;
						width: calc(100% - 200rpx);
					}
				}
			}
			
			.ranking-list-item{
				height: 110rpx;
				display: flex;
				align-items: center;
				font-size: 14px;
				border-bottom: 1px solid #f0f0f0;
			
				.ranking-list-number{
					width: 100rpx;
					color: #777;
					display: flex;
					justify-content: center;
					
					image{
						width: 50rpx;
						height: 50rpx;
					}
				}
				
				.ranking-list-score{
					display: block;
					width: 100rpx;
					color: #E28935;
					font-size: 16px;
					text-align: center;
				}
				
				.ranking-list-nickname{
					display: flex;
					align-items: center;
					width: calc(100% - 200rpx);
					box-sizing: border-box;
					padding-left: 20rpx;
					
					image{
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}
					
					text{
						width: auto;
					}
				}
			}
		}
	}
</style>